import requests
from lxml import etree
from lxml.etree import HTMLParser
import json
import io
import sys

#改变标准输出的默认编码
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='gb18030')

def db_music(url):
	'''
	新世纪
	'''
	# proxies = {
	# 	"http": "203.124.53.25:45780",
	# 	"https": "http://75.128.209.158:8080",
	# }
	l_response = requests.get(url)
	body = l_response.text
	dicts = json.loads(body)
	item_dict = {}
	item_list = []
	for d in dicts:
		item_dict = {
			'des':d['description'],
			'c_picture': d['creator']['picture'],
			'c_url':d['creator']['url'],
			's_artist': d['sample_songs'][1]['artist'],
			'duration': d['duration'],
			'm_id': d['id'],
			'songs_count': d['songs_count'],
			'collected_count': d['collected_count'],
			'title': d['title'],
			'cover':d['cover'],
			'updated_time': d['updated_time']
		}
		item_list.append(item_dict)
		
	return item_list

if __name__ == '__main__':
	url = 'https://douban.fm/j/v2/songlist/explore?type=hot&genre=15&limit=20&sample_cnt=5'
	item_list = db_music(url)
	print(item_list)